package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.TeacherReportDetailItemBean;
import com.fancy.learncenter.ui.activity.CartoonTeacherReportContentListActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;

import java.util.List;

/**
 * Created by shiweiwei on 2018/1/26.
 */

public class TeacherReportDetailAdapter extends CommonRecycleViewAdapter<TeacherReportDetailItemBean> {
    public TeacherReportDetailAdapter(Context mContext, List<TeacherReportDetailItemBean> itemDatas) {
        super(mContext, R.layout.teacher_report_detail_item_layout, itemDatas);
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final TeacherReportDetailItemBean item, final int position) {

        TextView urge_text = customViewHold.getView(R.id.urge_text);
        TextView right_arrow = customViewHold.getView(R.id.right_arrow);
        SimpleDraweeView head_icon = customViewHold.getView(R.id.head_icon);
        TextView head_name = customViewHold.getView(R.id.head_name);
        TextView percentage_text = customViewHold.getView(R.id.percentage_text);
        TextView commit_times = customViewHold.getView(R.id.commit_times);

        if (!"未完成".equals(item.getRightRate())) {

            urge_text.setVisibility(View.GONE);
            right_arrow.setVisibility(View.VISIBLE);

            customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent intent = new Intent(mContext, CartoonTeacherReportContentListActivity.class);
                    intent.putExtra("commitCount", item.getCommitCount());
                    intent.putExtra("studentHomeworkId", item.getStudentHomeworkId());
                    intent.putExtra("studentName", item.getStudentName());
                    intent.putExtra("homePackageId", homePackageId);
                    mContext.startActivity(intent);

                }
            });

        } else {
            right_arrow.setVisibility(View.GONE);
            if ("0".equals(item.getIsNotify())) {
                urge_text.setText("催促");
                urge_text.setTextColor(Color.parseColor("#00C9B9"));

                urge_text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (urgeCallBackl != null) {
                            urgeCallBackl.urgeCallBackClick(item.getStudentHomeworkId(), position);
                        }
                    }
                });
            } else {
                urge_text.setText("已催");
                urge_text.setTextColor(Color.parseColor("#9D9D9D"));
            }
        }
        commit_times.setText(item.getCommitCount() + "次");

        head_icon.setImageURI(item.getHeadImgurl());
        if (!TextUtils.isEmpty(item.getStudentName())) {
            head_name.setText(item.getStudentName());
        }

        if (!TextUtils.isEmpty(item.getRightRate())) {
            percentage_text.setText(item.getRightRate());
        }

    }

    private String homePackageId;

    public String getHomePackageId() {
        return homePackageId;
    }

    public void setHomePackageId(String homePackageId) {
        this.homePackageId = homePackageId;
    }

    private UrgeCallBack urgeCallBackl;

    public UrgeCallBack getUrgeCallBackl() {
        return urgeCallBackl;
    }

    public void setUrgeCallBackl(UrgeCallBack urgeCallBackl) {
        this.urgeCallBackl = urgeCallBackl;
    }

    public interface UrgeCallBack {
        abstract void urgeCallBackClick(String studentHomeworkId, int position);
    }


}
